package org.stone.project.tx.utils;

import cn.hutool.json.JSONUtil;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.stone.project.tx.pojo.dto.TxRespPojo;
import org.stone.project.tx.sysEnum.MsgType;

public class ResultUtil {
    public  static <T> TextWebSocketFrame ok(MsgType msgType,String msg,T data){
        TxRespPojo<T> objectTxRespPojo = new TxRespPojo<>();
        objectTxRespPojo.setType(msgType.code);
        objectTxRespPojo.setData(data);
        objectTxRespPojo.setStatus(1);
        objectTxRespPojo.setMsg(msg);
        return new TextWebSocketFrame(JSONUtil.toJsonStr(objectTxRespPojo));
    }

    public  static <T> TextWebSocketFrame ok(MsgType msgType,T data){
        TxRespPojo<T> objectTxRespPojo = new TxRespPojo<>();
        objectTxRespPojo.setType(msgType.code);
        objectTxRespPojo.setStatus(1);
        objectTxRespPojo.setData(data);
        return new TextWebSocketFrame(JSONUtil.toJsonStr(objectTxRespPojo));
    }

    public  static <T> TextWebSocketFrame ok(MsgType msgType){
        TxRespPojo<T> objectTxRespPojo = new TxRespPojo<>();
        objectTxRespPojo.setStatus(1);
        objectTxRespPojo.setType(msgType.code);
        return new TextWebSocketFrame(JSONUtil.toJsonStr(objectTxRespPojo));
    }

    public static <T> TextWebSocketFrame fail(MsgType msgType,String msg){
        TxRespPojo<Object> objectTxRespPojo = new TxRespPojo<>();
        objectTxRespPojo.setType(msgType.code);
        objectTxRespPojo.setStatus(0);
        objectTxRespPojo.setMsg(msg);
        return new TextWebSocketFrame(JSONUtil.toJsonStr(objectTxRespPojo));
    }
}
